﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK.Graphics.OpenGL;
namespace Foundry.Graphics
{
	/// <summary>
	/// Contains and index buffer. This is used to index vertices in a vertex buffer in order to render out of order triangles, and use shared vertices. 
	/// </summary>
    public sealed class IndexBuffer<T> : Buffer<T>
        where T : struct
    {
        public DrawElementsType ElementsType { get; private set; }
        public IndexBuffer()
            : base(OpenTK.Graphics.OpenGL.BufferTarget.ElementArrayBuffer)
        {
            if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte))
                ElementsType = DrawElementsType.UnsignedByte;
            else if (typeof(T) == typeof(ushort) || typeof(T) == typeof(short))
                ElementsType = DrawElementsType.UnsignedShort;
            else if (typeof(T) == typeof(uint) || typeof(T) == typeof(int))
                ElementsType = DrawElementsType.UnsignedInt;
            else
                throw new NotSupportedException("Invalid datatype in indexbuffer");
            
        }
    }
}
